unit RelatorioDM;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, DB, FileUtil, LR_Class, LR_DBSet, LR_BarC, lr_e_pdf,
  LResources, Forms, Controls, Graphics, Dialogs, ZDataset, MainDM;

type

  { TRelatorioData }

  TRelatorioData = class(TMainDataModule)
    DetalheZQueryareia: TFloatField;
    DetalheZQueryargila: TFloatField;
    DetalheZQueryclassificacao: TStringField;
    DetalheZQueryid_amostra: TLongintField;
    DetalheZQueryid_analise: TLongintField;
    DetalheZQuerypeso_becker_1: TLongintField;
    DetalheZQuerypeso_becker_2: TLongintField;
    DetalheZQuerypeso_volume_pipetado_1: TLongintField;
    DetalheZQuerypeso_volume_pipetado_2: TLongintField;
    DetalheZQueryreferencia_cliente: TStringField;
    DetalheZQueryreferencia_laboratorio: TLongintField;
    DetalheZQuerysilte: TFloatField;
    ExportDialog: TSaveDialog;
    PrincipalBarCode: TfrBarCodeObject;
    PrincipalPDFExport: TfrTNPDFExport;
    PrincipalReport: TfrReport;
    RelatorioDataSource: TDatasource;
    RelatorioDataSet: TfrDBDataSet;
    RelatorioZQuery: TZReadOnlyQuery;
    RelatorioZQuerycodigo_barra: TStringField;
    procedure DataModuleCreate(Sender: TObject);
    procedure SalvaPDF(CodigoBarra: string);
    procedure MostraRelatorio(CodigoBarra: string);
    procedure GeraRelatorio(CodigoBarra: string);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  RelatorioData: TRelatorioData;

implementation

uses ConnectionDM;


procedure TRelatorioData.GeraRelatorio(CodigoBarra: string);
begin
  with RelatorioZQuery do begin
    RelatorioZQuery.Close();
    RelatorioZQuery.SQL.Clear;
    RelatorioZQuery.SQL.Add('SELECT codigo_barra FROM produto');
    RelatorioZQuery.SQL.Add('WHERE codigo_barra=:codigo');
    RelatorioZQuery.ParamByName('codigo').AsString := CodigoBarra;
  end;
  RelatorioZQuery.Active := True;
  RelatorioData.PrincipalReport.LoadFromFile('relatorio/RelatorioCodigoBarra.lrf');
end;

procedure TRelatorioData.MostraRelatorio(CodigoBarra: string);
begin
  GeraRelatorio(CodigoBarra);
  RelatorioData.PrincipalReport.ShowReport();
end;


procedure TRelatorioData.SalvaPdf(CodigoBarra: string);
begin
  ExportDialog.InitialDir := GetUserDir();
  if (ExportDialog.Execute) then begin
    GeraRelatorio(CodigoBarra);
    PrincipalReport.PrepareReport;
    PrincipalReport.ExportTo(TfrTNPDFExportFilter, ExportDialog.FileName);
  end;
end;

procedure TRelatorioData.DataModuleCreate(Sender: TObject);
begin
  MainDataSet:= RelatorioZQuery;
end;

initialization
  {$I relatoriodm.lrs}

end.



